// To parse this JSON data, do
//
//     final searchListResp = searchListRespFromJson(jsonString);

import 'dart:convert';

SearchListResp searchListRespFromJson(String str) => SearchListResp.fromJson(json.decode(str));

String welcomeToJson(SearchListResp data) => json.encode(data.toJson());

class SearchListResp {
    SearchListData data;
    int errorCode;
    String errorMsg;

    SearchListResp({
        required this.data,
        required this.errorCode,
        required this.errorMsg,
    });

    factory SearchListResp.fromJson(Map<String, dynamic> json) => SearchListResp(
        data: SearchListData.fromJson(json["data"]),
        errorCode: json["errorCode"],
        errorMsg: json["errorMsg"],
    );

    Map<String, dynamic> toJson() => {
        "data": data.toJson(),
        "errorCode": errorCode,
        "errorMsg": errorMsg,
    };
}

class SearchListData {
    int curPage;
    List<SearchListItem> datas;
    int offset;
    bool over;
    int pageCount;
    int size;
    int total;

    SearchListData({
        required this.curPage,
        required this.datas,
        required this.offset,
        required this.over,
        required this.pageCount,
        required this.size,
        required this.total,
    });

    factory SearchListData.fromJson(Map<String, dynamic> json) => SearchListData(
        curPage: json["curPage"],
        datas: List<SearchListItem>.from(json["datas"].map((x) => SearchListItem.fromJson(x))),
        offset: json["offset"],
        over: json["over"],
        pageCount: json["pageCount"],
        size: json["size"],
        total: json["total"],
    );

    Map<String, dynamic> toJson() => {
        "curPage": curPage,
        "datas": List<dynamic>.from(datas.map((x) => x.toJson())),
        "offset": offset,
        "over": over,
        "pageCount": pageCount,
        "size": size,
        "total": total,
    };
}

class SearchListItem {
    bool adminAdd;
    String apkLink;
    int audit;
    // Author author;
    String author;
    bool canEdit;
    int chapterId;
    String chapterName;
    bool collect;
    int courseId;
    String desc;
    String descMd;
    String envelopePic;
    bool fresh;
    String host;
    int id;
    bool isAdminAdd;
    String link;
    String niceDate;
    String niceShareDate;
    String origin;
    String prefix;
    String projectLink;
    int publishTime;
    int realSuperChapterId;
    int selfVisible;
    int shareDate;
    String shareUser;
    int superChapterId;
    // Name superChapterName;
    String superChapterName;
    List<Tag?> tags;
    String title;
    int type;
    int userId;
    int visible;
    int zan;

    SearchListItem({
        required this.adminAdd,
        required this.apkLink,
        required this.audit,
        required this.author,
        required this.canEdit,
        required this.chapterId,
        required this.chapterName,
        required this.collect,
        required this.courseId,
        required this.desc,
        required this.descMd,
        required this.envelopePic,
        required this.fresh,
        required this.host,
        required this.id,
        required this.isAdminAdd,
        required this.link,
        required this.niceDate,
        required this.niceShareDate,
        required this.origin,
        required this.prefix,
        required this.projectLink,
        required this.publishTime,
        required this.realSuperChapterId,
        required this.selfVisible,
        required this.shareDate,
        required this.shareUser,
        required this.superChapterId,
        required this.superChapterName,
        required this.tags,
        required this.title,
        required this.type,
        required this.userId,
        required this.visible,
        required this.zan,
    });

    factory SearchListItem.fromJson(Map<String, dynamic> json) => SearchListItem(
        adminAdd: json["adminAdd"],
        apkLink: json["apkLink"],
        audit: json["audit"],
        // author: authorValues.map[json["author"]]!,
        author: json["author"],
        canEdit: json["canEdit"],
        chapterId: json["chapterId"],
        chapterName: json["chapterName"],
        collect: json["collect"],
        courseId: json["courseId"],
        desc: json["desc"],
        descMd: json["descMd"],
        envelopePic: json["envelopePic"],
        fresh: json["fresh"],
        host: json["host"],
        id: json["id"],
        isAdminAdd: json["isAdminAdd"],
        link: json["link"],
        niceDate: json["niceDate"],
        niceShareDate: json["niceShareDate"],
        origin: json["origin"],
        prefix: json["prefix"],
        projectLink: json["projectLink"],
        publishTime: json["publishTime"],
        realSuperChapterId: json["realSuperChapterId"],
        selfVisible: json["selfVisible"],
        shareDate: json["shareDate"],
        shareUser: json["shareUser"],
        superChapterId: json["superChapterId"],
        // superChapterName: nameValues.map[json["superChapterName"]]!,
        superChapterName: json["superChapterName"],
        tags: List<Tag>.from(json["tags"].map((x) => Tag.fromJson(x))),
        title: json["title"],
        type: json["type"],
        userId: json["userId"],
        visible: json["visible"],
        zan: json["zan"],
    );

    Map<String, dynamic> toJson() => {
        "adminAdd": adminAdd,
        "apkLink": apkLink,
        "audit": audit,
        // "author": authorValues.reverse[author],
        "author": author,
        "canEdit": canEdit,
        "chapterId": chapterId,
        "chapterName": chapterName,
        "collect": collect,
        "courseId": courseId,
        "desc": desc,
        "descMd": descMd,
        "envelopePic": envelopePic,
        "fresh": fresh,
        "host": host,
        "id": id,
        "isAdminAdd": isAdminAdd,
        "link": link,
        "niceDate": niceDate,
        "niceShareDate": niceShareDate,
        "origin": origin,
        "prefix": prefix,
        "projectLink": projectLink,
        "publishTime": publishTime,
        "realSuperChapterId": realSuperChapterId,
        "selfVisible": selfVisible,
        "shareDate": shareDate,
        "shareUser": shareUser,
        "superChapterId": superChapterId,
        // "superChapterName": nameValues.reverse[superChapterName],
        "superChapterName": superChapterName,
        "tags": List<dynamic>.from(tags.map((x) => x?.toJson())),
        "title": title,
        "type": type,
        "userId": userId,
        "visible": visible,
        "zan": zan,
    };
}

enum Author {
    AUTHOR,
    EMPTY,
    PURPLE
}

final authorValues = EnumValues({
    "": Author.AUTHOR,
    "郭霖": Author.EMPTY,
    "鸿洋": Author.PURPLE
});

enum Name {
    APP,
    EMPTY,
    NAME_TAB,
    TAB
}

final nameValues = EnumValues({
    "鸿蒙App开发入门 - 学习路径": Name.APP,
    "公众号": Name.EMPTY,
    "鸿蒙Tab": Name.NAME_TAB,
    "广场Tab": Name.TAB
});

class Tag {
    String name;
    String url;

    Tag({
        required this.name,
        required this.url,
    });

    factory Tag.fromJson(Map<String, dynamic> json) => Tag(
        // name: nameValues.map[json["name"]]!,
        name: json["name"],
        url: json["url"],
    );

    Map<String, dynamic> toJson() => {
        // "name": nameValues.reverse[name],
        "name": name,
        "url": url,
    };
}

class EnumValues<T> {
    Map<String, T> map;
    late Map<T, String> reverseMap;

    EnumValues(this.map);

    Map<T, String> get reverse {
            reverseMap = map.map((k, v) => MapEntry(v, k));
            return reverseMap;
    }
}
